﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _72重写练习_重写ToString
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Student s = new Student("张三", 15);
            Student s1 = new Student("张三", 15);
            Student s2 = new Student("张三", 16);
            Console.WriteLine(s.ToString());//张三
            Console.WriteLine(s.Equals(s1));//True
            Console.WriteLine(s.Equals(s2));//false
        }
    }

    internal class Student
    {
        public string name;
        public int age;
        public Student(string name, int age)
        {
            this.name = name;
            this.age = age;
        }

        public override string ToString()
        {
            return name;
        }
        public override bool Equals(object obj)
        {
            Student other = obj as Student;
            return other == null ? false : this.name == other.name && this.age == other.age;
        }
    }
}